package com.wcards.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcards.config.R;
import com.wcards.dto.PasswordDTO;
import com.wcards.entity.UserInfo;
import com.wcards.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 大黑
 */
@Api("用户信息模块")
@RestController
@Slf4j
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;

    /*
    登录
     */
    @ApiOperation(value = "用户登录接口")
    @PostMapping("/login")
    public R<String> login(@RequestBody UserInfo userInfo, HttpServletRequest request) {
        return userInfoService.userLogin(userInfo, request);
    }

    /*
    注册
     */
    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public R<String> register(@RequestBody UserInfo userInfo) {
        return userInfoService.register(userInfo);
    }

    /*
    注销
     */
    @ApiOperation("用户注销接口")
    @DeleteMapping("/logOut")
    public R<String> logOut(Integer userId) {
        return userInfoService.logOut(userId);
    }

    /*
    用户修改基本信息
     */
    @ApiOperation(value = "用户修改基本信息")
    @PutMapping("/updateIdentity")
    public R<String> updateIdentity(@RequestBody UserInfo userInfo) {
        return userInfoService.updateIdentity(userInfo);
    }

    /*
    用户修改密码
     */
    @ApiOperation(value = "用户修改密码")
    @PutMapping("/updatePassword")
    public R<String> updatePassword(@RequestBody PasswordDTO passwordDTO) {
        return userInfoService.updatePassword(passwordDTO);
    }

    /*
    查看所有用户
     */
    @ApiOperation(value = "查看所有用户")
    @GetMapping("/findUsers")
    public R<Page<UserInfo>> findUsers(String phone, String userName, Integer userStatus, Integer pageSize, Integer pageNumber) {
        return userInfoService.findUsers(pageSize, pageNumber, phone, userName, userStatus);
    }

    /*
    启用禁用用户
     */
    @ApiOperation(value = "启用禁用用户")
    @PutMapping("/updateStates")
    public R<String> updateStates(Integer userId) {
        return userInfoService.updateStates(userId);
    }

    /*
    根据Id查询用户所有信息
     */
    @ApiOperation(value = "查看用户详情")
    @GetMapping("/findById")
    public R<UserInfo> findById(Integer userId) {
        return userInfoService.findById(userId);
    }

    /*
    查看所有的用户
     */
    @ApiOperation(value = "查看所有的用户")
    @GetMapping("/findAllUsers")
    public R<Page<UserInfo>> findAllUsers(Integer pageSize, Integer pageNumber, HttpServletRequest request) {
        return userInfoService.findAllUsers(pageSize, pageNumber);
    }
}
